<template>
  <div>
    <!-- 表单 -->
    <el-table :data="mylist"
              border
              style="width: 100%">
      <el-table-column fixed
                       type="index"
                       label="序号">
      </el-table-column>
      <el-table-column prop="date"
                       label="创建时间">
                       <template slot-scope="scope">
                        <span>{{scope.row.date | formTime}}</span>
                       </template>
      </el-table-column>
      <el-table-column prop="type"
                       label="收支类型">
      </el-table-column>
      <el-table-column prop="describe"
                       label="收支描述">
      </el-table-column>
      <el-table-column prop="income"
                       label="收入">
      </el-table-column>
      <el-table-column prop="expend"
                       label="支出">
      </el-table-column>
      <el-table-column fixed="right"
                       label="操作">
        <template slot-scope="scope">
          <el-button @click="editor(scope.row._id)"
                     type="text"
                     size="small">编辑</el-button>
          <el-button type="text"
                     size="small"
                     @click="del(scope.row._id)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>
<script>
export default {
  props: ['mylist','list'],
  name: 'myform',
  data() {
    return {}
  },
  created() {
  },
  methods: {
    del(id) {
      this.$emit('del', id)
      console.log(this.list);
    },
    editor(id){
      this.$emit('editor',id)
    }
  },
  filters:{
    formTime(val){
      // 转为北京时间
      let time = new Date(val);
      let year = time.getFullYear();
      let obj ={
        month:time.getMonth()+1,
        day:time.getDate(),
        hour:time.getMinutes(),
        second:time.getSeconds(),
      };
      for (let i in obj){
        obj[i] = obj[i]<10?'0'+obj[i]:obj[i]
      }
      return `${year}-${obj.month}-${obj.day}:${obj.hour}:${obj.second}`
    }
  }
}
</script>